/**
 * 
 */
package com.demo.web.admin.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.utils.ReferenceConfigCache;
import com.alibaba.dubbo.rpc.service.GenericService;

/**
 * @author CaoHenghui
 *
 */
@Service
public class PayService {
	
	@Autowired
	private ApplicationConfig applicationConfig;
	
	@Autowired
	private RegistryConfig registryConfig;
	
	
	/**
	 * @param payChannel 支付渠道
	 * @return
	 */
	public Object pay(Map<String,Object> data,String payChannel) {
		ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<GenericService>();
		referenceConfig.setApplication(applicationConfig);
        referenceConfig.setRegistry(registryConfig);
        referenceConfig.setVersion(payChannel);
        referenceConfig.setInterface("com.demo.test.rpc.api.IPay");
        referenceConfig.setGeneric(true);
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        Object result = cache.get(referenceConfig).$invoke("pay", new String[] {"java.util.Map","java.lang.String"}, new Object[] {data,payChannel});
		return result;
	}

}
